package com.nmsl.membership.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.membership.domain.MembershipLevel;
import com.nmsl.membership.service.IMembershipLevelService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 会员设置Controller
 * 
 * @author liuyan
 * @date 2025-02-15
 */

//会员设置
@RestController
@RequestMapping("/membership/vipconfig")
public class MembershipLevelController extends BaseController
{
    @Autowired
    private IMembershipLevelService membershipLevelService;

    /**
     * 查询会员设置列表
     */
//    @PreAuthorize("@ss.hasPermi('membership:vipconfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(MembershipLevel membershipLevel)
    {
        startPage();
        List<MembershipLevel> list = membershipLevelService.selectMembershipLevelList(membershipLevel);
        return getDataTable(list);
    }

    /**
     * 导出会员设置列表
     */
    @PreAuthorize("@ss.hasPermi('membership:vipconfig:export')")
    @Log(title = "会员设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MembershipLevel membershipLevel)
    {
        List<MembershipLevel> list = membershipLevelService.selectMembershipLevelList(membershipLevel);
        ExcelUtil<MembershipLevel> util = new ExcelUtil<MembershipLevel>(MembershipLevel.class);
        util.exportExcel(response, list, "会员设置数据");
    }

    /**
     * 获取会员设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('membership:vipconfig:query')")
    @GetMapping(value = "/{levelId}")
    public AjaxResult getInfo(@PathVariable("levelId") Long levelId)
    {
        return success(membershipLevelService.selectMembershipLevelByLevelId(levelId));
    }

    /**
     * 新增会员设置
     */
//    @PreAuthorize("@ss.hasPermi('membership:vipconfig:add')")
//    @Log(title = "会员设置", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody MembershipLevel membershipLevel)
//    {
//        return toAjax(membershipLevelService.insertMembershipLevel(membershipLevel));
//    }
    @PreAuthorize("@ss.hasPermi('membership:vipconfig:query')")
    @PostMapping
    public AjaxResult add(@RequestBody MembershipLevel membershipLevel){
        return toAjax(membershipLevelService.insertMembershipLevel(membershipLevel));
    }


    /**
     * 修改会员设置
     */
    @PreAuthorize("@ss.hasPermi('membership:vipconfig:edit')")
    @Log(title = "会员设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MembershipLevel membershipLevel)
    {
        return toAjax(membershipLevelService.updateMembershipLevel(membershipLevel));
    }

    /**
     * 删除会员设置
     */
    @PreAuthorize("@ss.hasPermi('membership:vipconfig:remove')")
    @Log(title = "会员设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{levelIds}")
    public AjaxResult remove(@PathVariable Long[] levelIds)
    {
        return toAjax(membershipLevelService.deleteMembershipLevelByLevelIds(levelIds));
    }
}
